-- SPDX-License-Identifier: GPL-3.0-or-later

local v_youlan = fk.CreateSkill {
  name = "v_youlan",
  --技能为锁定技，满足条件后强制发动
  tags = { Skill.Compulsory, },
}

  --时机：受到伤害时，造成伤害时
v_youlan:addEffect(fk.DamageInflicted, {
  --(非必要）赋予特殊型技能定义
  anim_type = "special",
  events = {fk.DamageInflicted,fk.DamageCaused},
  --触发条件：
  --触发时机的角色为遍历到的角色、遍历到的角色具有本技能、牌为实体牌、牌的种类为锦囊牌、造成的伤害大于0。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(v_youlan.name) and
      (data.card and data.card.type == Card.TypeTrick)  and data.damage > 0
  end,
  on_use = function(self, event, target, player, data)
    -- local room = player.room
    -- local address = "./packages/"..VslUtil.extensionName.."/image/skill/qihaiyouxian_2"
    -- room:setEmotion(player, address)
    data.damage = data.damage - 1
    -- if data.damage <= 0 then
    --   address = "./packages/"..VslUtil.extensionName.."/image/anim/skill_nullify"
    --   room:setEmotion(player, address)
    -- end
  end,
})

v_youlan:addEffect(fk.DamageCaused, {
  --(非必要）赋予特殊型技能定义
  anim_type = "special",
  --触发条件：
  --造成伤害的来源为遍历到的角色、遍历到的角色具有本技能、牌为实体牌、牌的种类为锦囊牌、造成的伤害大于0。
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(v_youlan.name) and
      (data.card and data.card.type == Card.TypeTrick)  and data.damage > 0
  end,
  on_use = function(self, event, target, player, data)
    -- local room = player.room
    -- local address = "./packages/"..VslUtil.extensionName.."/image/skill/qihaiyouxian_1"
    -- room:setEmotion(player, address)
    data.damage = data.damage + 1
  end,
})

-- v_youlan:addAI({
--   think = function(self, ai)
--     local cards = ai:getEnabledCards()
--     if #cards < 2 then return "" end

--     local cancel_val = ai:getBenefitOfEvents(function(logic)
--       logic:damage{
--         from = ai.room.logic:getCurrentEvent().data[2],
--         to = ai.player,
--         damage = 1,
--         skillName = self.skill.name,
--       }
--     end)
--     local to_discard, discard_val = ai:askToDiscard({
--       min_num = 2,
--       max_num = 2,
--       skill_name = self.skill.name,
--       cancelable = false,
--     })

--     if discard_val > cancel_val then
--       return { cards = to_discard }
--     else
--       return ""
--     end
--   end,

--   think_skill_invoke = function(self, ai, skill_name, prompt)
--     ---@type DamageData
--     local dmg = ai.room.logic:getCurrentEvent().data
--     local from = dmg.from
--     if not from then return false end
--     local dmg_val = ai:getBenefitOfEvents(function(logic)
--       logic:damage{
--         from = ai.player,
--         to = from,
--         damage = 1,
--         skillName = self.skill.name,
--       }
--     end)
--     local discard_val = ai:getBenefitOfEvents(function(logic)
--       local cards = from:getCardIds("h")
--       if #cards < 2 then
--         logic.benefit = -1
--         return
--       end
--       logic:throwCard(table.random(cards, 2), self.skill.name, from, from)
--     end)
--     if dmg_val > 0 or discard_val > 0 then
--       return true
--     end
--     return false
--   end,
-- })

-- v_youlan:addAI({
--   correct_func = function(self, logic, event, target, player, data)
--     if target:hasSkill(v_youlan.name) then
      
--     end
--     -- if self.skill:triggerable(event, target, player, data) then
--     --   data.num = data.num + 1
--     -- end
--   end,
-- }, nil, nil, true)

return v_youlan